package com.example.homework.utils;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.example.homework.R;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

/**
 * 模拟数据
 */
public class DataMaker {

    private static int[] pictrue = {R.drawable.a000, R.drawable.a001, R.drawable.a002, R.drawable.a003,
            R.drawable.a004, R.drawable.a005, R.drawable.a006, R.drawable.a007, R.drawable.a008,
            R.drawable.a009};
    private static String[] title = {"2019秋装新款白色纯棉长袖t恤女装宽松春秋打底衫体恤大码上衣", "2019初秋新款潮韩版洋气女装宽松秋季短款衬衫女秋装方领长袖上衣",
            "纯棉长袖T恤女上衣2019新款竹节棉宽松秋衣女装薄款初秋打底衫潮", "半高领打底衫女装秋冬薄款洋气莫代尔堆堆领长袖t恤内搭针织上衣",
            "女装2019新款潮超火cec短袖女春夏季港味宽松百搭上衣T恤ins洋气", "夏大大胖mm韩版宽松秋装新款女装大码2019牛仔套装外套减龄连衣裙",
            "大姗姗家瘦瘦裤胖mm韩版大码女装秋季百搭外穿打底裤网红款小脚裤", "中国大陆','夏装紧身纯白色T恤女短袖修身女装女士纯棉2019新款上衣潮打底衫",
            "纯棉长袖T恤女上衣2019新款竹节棉宽松秋衣女装薄款初秋打底衫潮", "纯棉红色v领T恤女短袖修身夏女装2019新款潮体恤紧身上衣黑色短款",};
    private static String[] location = {"云南 昆明", "广东 广州", "江西 南昌", "广东 汕头", "浙江 金华", "广东 广州", "江苏 淮安",
            "江苏 苏州", "广东 深圳", "安徽 芜湖"};
    private static String[] shop = {"lovtis兰蒂斯旗舰店", "lovtis兰蒂斯旗舰店", "lovtis兰蒂斯旗舰店", "lovtis兰蒂斯旗舰店",
            "旗舰店", "旗舰店", "旗舰店", "旗舰店", "旗舰店", "旗舰店"};
    private static String[] number = {"87816", "37384", "62165", "43221", "4561", "43211", "3011",
            "764", "7656", "4567"};
    private static String[] prices = {"39.9", "29.87", "29", "56", "20", "138", "97", "15", "78", "30"};



    public static List<GoodInfo> makeGoodList(){
        List<GoodInfo> fakeGoodInfos =makeFakeGoodInfos();
        List<GoodInfo> goodList = new ArrayList<GoodInfo>();
        for (int i = 0; i < 10; i++) {
            GoodInfo good = fakeGoodInfos.get(i);
            good.setImage(pictrue[i]);
            good.setName(title[i]);
            good.setProductLocation(location[i]);
            good.setShopName(shop[i]);
            good.setPrice(prices[i]);
            good.setVolume(number[i]);
            goodList.add(good);
        }
        return goodList;
    }


    private static List<GoodInfo> makeFakeGoodInfos(){
        String data = "[{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/101.jpg\",\"productLocation\":\"上海\",\"name\":\"HBay纽湾新西兰进口矿泉水500ml*24天然饮用水小瓶装水母婴水整箱\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":49.8,\"volume\":\"4507\",\"shopName\":\"纽湾旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/102.jpg\",\"productLocation\":\"上海\",\"name\":\"农夫山泉婴儿水1L*6瓶量贩装饮用天然水母婴水宝宝水适合婴幼儿\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":45.0,\"volume\":\"9001\",\"shopName\":\"天猫超市\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/103.jpg\",\"productLocation\":\"上海\",\"name\":\"农夫山泉饮用天然水（适合婴幼儿）1L/瓶 母婴水\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":11.0,\"volume\":\"1635\",\"shopName\":\"天猫超市\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/104.jpg\",\"productLocation\":\"广东 广州\",\"name\":\"母婴包轻便双肩包女手提书包多功能妈妈包大容量外出旅行防盗背包\",\"info\":\"分类：箱包皮具/热销女包/男包\\t分类：双肩背包\",\"price\":118.0,\"volume\":\"3760\",\"shopName\":\"lovtis兰蒂斯旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/105.jpg\",\"productLocation\":\"浙江 绍兴\",\"name\":\"棉居棉柔巾干湿两用一次性洗脸巾女纯棉洁面巾母婴擦脸巾1包100抽\",\"info\":\"分类：洗护清洁剂/卫生巾/纸/香薰\\t分类：棉柔巾/洗脸巾\",\"price\":16.9,\"volume\":\"2636\",\"shopName\":\"棉居旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/119.jpg\",\"productLocation\":\"山东 淄博\",\"name\":\"猪年婴儿礼盒套装男女宝宝新生儿纯棉衣服母婴用品刚出生满月礼物\",\"info\":\"分类：童装/婴儿装/亲子装\\t分类：婴儿礼盒\",\"price\":179.0,\"volume\":\"617\",\"shopName\":\"爱婴海母婴专营店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/115.jpg\",\"productLocation\":\"浙江 杭州\",\"name\":\"【农夫山泉官方旗舰店】天然矿泉水适合婴儿水母婴饮用1L*8瓶整箱\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：矿泉水/纯净水\",\"price\":64.9,\"volume\":\"2065\",\"shopName\":\"农夫山泉官方旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/117.jpg\",\"productLocation\":\"北京\",\"name\":\"牛津布多功能大容量双肩包女书包宝妈带娃背包旅行出门母婴包外出\",\"info\":\"分类：箱包皮具/热销女包/男包\\t分类：双肩背包\",\"price\":69.0,\"volume\":\"1285\",\"shopName\":\"阿加莎箱包旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/118.jpg\",\"productLocation\":\"上海\",\"name\":\"农夫山泉婴儿水1L*12瓶整箱 母婴矿泉水婴儿直饮水低钠 多省包邮\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：矿泉水/纯净水\",\"price\":89.9,\"volume\":\"30\",\"shopName\":\"名泉食品专营店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/116.jpg\",\"productLocation\":\"四川 成都\",\"name\":\"峨眉钰泉 天然矿泉水整箱520ml*24瓶母婴可饮用网红PK纯净饮用水\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":69.9,\"volume\":\"268\",\"shopName\":\"峨眉钰泉旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/114.jpg\",\"productLocation\":\"上海\",\"name\":\"新西兰进口HBay纽湾母婴水10L弱碱性天然饮用水婴儿矿泉水整箱\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":68.8,\"volume\":\"931\",\"shopName\":\"纽湾旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/107.jpg\",\"productLocation\":\"上海\",\"name\":\"农夫山泉婴儿水1L*8/箱饮用天然水母婴水宝宝水适合婴幼儿\",\"info\":\"分类：奶粉/辅食/营养品/零食\\t分类：果汁/饮品\",\"price\":59.9,\"volume\":\"383\",\"shopName\":\"天猫超市\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/112.jpg\",\"productLocation\":\"上海\",\"name\":\"童泰礼盒初生婴儿秋冬套装新生儿宝宝满月衣服母婴用品刚出生礼物\",\"info\":\"分类：童装/婴儿装/亲子装\\t分类：婴儿礼盒\",\"price\":168.0,\"volume\":\"825\",\"shopName\":\"童泰上海专卖店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/108.jpg\",\"productLocation\":\"上海\",\"name\":\"新西兰 原装进口27000冰川天然饮用水母婴儿水10L整箱非矿泉水\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":69.9,\"volume\":\"1359\",\"shopName\":\"天猫超市\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/113.jpg\",\"productLocation\":\"福建 厦门\",\"name\":\"婴儿用品大全新生儿礼盒0-3-24个月宝宝礼品衣服玩具礼物套装母婴\",\"info\":\"分类：童装/婴儿装/亲子装\\t分类：婴儿礼盒\",\"price\":139.0,\"volume\":\"1945\",\"shopName\":\"天空向我靠拢\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/110.jpg\",\"productLocation\":\"山东 淄博\",\"name\":\"婴儿礼盒宝宝出生满月礼物初生婴儿衣服套装新生儿秋冬季母婴用品\",\"info\":\"分类：童装/婴儿装/亲子装\\t分类：婴儿礼盒\",\"price\":148.0,\"volume\":\"1503\",\"shopName\":\"哈必宠旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/111.jpg\",\"productLocation\":\"山东 淄博\",\"name\":\"新生儿婴儿衣服礼盒套装初生宝宝满月礼物刚出生纯棉母婴用品大全\",\"info\":\"分类：童装/婴儿装/亲子装\\t分类：婴儿礼盒\",\"price\":69.0,\"volume\":\"863\",\"shopName\":\"天狼母婴专营店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/109.jpg\",\"productLocation\":\"上海\",\"name\":\"亿斯天然水 加拿大原装进口天然饮用水 420ml*12  母婴矿泉水进口\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":39.9,\"volume\":\"1123\",\"shopName\":\"亿斯旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/102.jpg\",\"productLocation\":\"上海\",\"name\":\"农夫山泉婴儿水1L*6瓶量贩装饮用天然水母婴水宝宝水适合婴幼儿\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":45.0,\"volume\":\"9001\",\"shopName\":\"天猫超市\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/104.jpg\",\"productLocation\":\"广东 广州\",\"name\":\"母婴包轻便双肩包女手提书包多功能妈妈包大容量外出旅行防盗背包\",\"info\":\"分类：箱包皮具/热销女包/男包\\t分类：双肩背包\",\"price\":118.0,\"volume\":\"3760\",\"shopName\":\"lovtis兰蒂斯旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/105.jpg\",\"productLocation\":\"浙江 绍兴\",\"name\":\"棉居棉柔巾干湿两用一次性洗脸巾女纯棉洁面巾母婴擦脸巾1包100抽\",\"info\":\"分类：洗护清洁剂/卫生巾/纸/香薰\\t分类：棉柔巾/洗脸巾\",\"price\":16.9,\"volume\":\"2636\",\"shopName\":\"棉居旗舰店\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/103.jpg\",\"productLocation\":\"上海\",\"name\":\"农夫山泉饮用天然水（适合婴幼儿）1L/瓶 母婴水\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":11.0,\"volume\":\"1635\",\"shopName\":\"天猫超市\"},{\"image\":\"http://10.3.66.199:8080/HappyShop/data/img/1/101.jpg\",\"productLocation\":\"上海\",\"name\":\"HBay纽湾新西兰进口矿泉水500ml*24天然饮用水小瓶装水母婴水整箱\",\"info\":\"分类：咖啡/麦片/冲饮\\t分类：饮用水\",\"price\":49.8,\"volume\":\"4507\",\"shopName\":\"纽湾旗舰店\"}]";
        List<GoodInfo> goodInfos= jsonToArrayList(data, GoodInfo.class);
         return goodInfos;
    }

    private static <T> ArrayList<T> jsonToArrayList(String json, Class<T> clazz) {
        Type type = new TypeToken<ArrayList<JsonObject>>() {
        }.getType();
        ArrayList<JsonObject> jsonObjects = new Gson().fromJson(json, type);

        ArrayList<T> list = new ArrayList<>();
        for (JsonObject jsonObject : jsonObjects) {
            jsonObject.remove("image");
            list.add(new Gson().fromJson(jsonObject, clazz));
        }
        return list;
    }
}
